/* 建立响应式数据 */
function reactive(target) {
	if (!target || typeof target !== "object") return target;

	const proxy = new Proxy(target, {
		get(target, key, receiver) {
			// 读取原属性的值
			const res = Reflect.get(target, key, receiver);
			// 跟踪、收集依赖
			track(target, key);
			// 建立深度响应式 --> 为了都进行track
			return reactive(res);
		},
		set(target, key, val, receiver) {
			// 更新原属性的值
			const res = Reflect.set(target, key, val, receiver);
			// 触发更新用户界面
			trigger(target, key);
			return res;
		},
		deleteProperty(target, key) {
			// 删除属性
			const res = Reflect.deleteProperty(target, key);
			// 触发更新用户界面
			trigger(target, key);
			return res;
		},
	});

	return proxy;
}
